package com.laker.autotest.core.retry;

import cn.hutool.extra.spring.SpringUtil;
import com.laker.autotest.config.EasyConfig;
import lombok.extern.slf4j.Slf4j;
import org.testng.ITestResult;
import org.testng.util.RetryAnalyzerCount;

@Slf4j
public class RetryAnalyzer extends RetryAnalyzerCount {
    public RetryAnalyzer() {
        EasyConfig config = SpringUtil.getBean(EasyConfig.class);
        setCount(config.getRetryOptions().maxRetryCount);
    }

    @Override
    public boolean retryMethod(ITestResult result) {
        String methodName = result.getMethod().getMethodName();
        String testName = result.getTestClass().getName();
        String suiteName = result.getTestContext().getSuite().getName();
        log.warn("Retrying test {} {}.{},remaining {} attempts.", suiteName, testName, methodName, getCount());
        return true;
    }

}